package db.read;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;

public class MyWritable implements Writable, DBWritable {
	// Some data
	private int counter;
	private long timestamp;

	// Writable#write() implementation
	public void write(DataOutput out) throws IOException {
		out.writeInt(counter);
		out.writeLong(timestamp);
	}

	// Writable#readFields() implementation
	public void readFields(DataInput in) throws IOException {
		counter = in.readInt();
		timestamp = in.readLong();
	}

	public void write(PreparedStatement statement) throws SQLException {
		statement.setInt(1, counter);
		statement.setLong(2, timestamp);
	}

	public void readFields(ResultSet resultSet) throws SQLException {
		counter = resultSet.getInt(1);
		timestamp = resultSet.getLong(2);
	}
}